import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import request from './utils/request'
Vue.config.productionTip = false
Vue.prototype.$request = request

Vue.use(ElementUI);


// 校验用户token
router.beforeEach((to,from,next)=>{
  const path = to.path;// /manage/,/manage/home,/manage/user
  // 判断目标路由路径是否以/manage开头
  // console.log('beforeEach')
  if(path.startsWith('/manage')){
    if(store.getters['user/isLogin']){
      const username = store.state.user.userInfo;
      // console.log(username);
      if(username){
        // console.log(username);
        next();
      }
      else{
        router.push('/user/login')
      }
    }else{
      router.push('/user/login')
    }
  }else{
    next();
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')